package com.javabasic2.Shootclient;

import java.awt.Graphics;
import java.util.Vector;

public class DrawBitmap {
	
	private Vector<UnitImage> iList;
	private Vector<BulletImage> iBullet;
	private BackgroundImage intro;
	private BackgroundImage background;
	//private Object key = new Object();
	public void setBackground(BackgroundImage background) {
		this.background = background;
	}
	public void setIntro(BackgroundImage intro) {
		this.intro = intro;
	}
	public DrawBitmap(){
		this.iList = new Vector<UnitImage>();
		this.iBullet = new Vector<BulletImage>();
	}
	public void add(UnitImage img) {
		iList.add(img);
	}
	public void addBullet(BulletImage img) {
		synchronized(iBullet) {
		//	if(iBullet.size() < 1)
			iBullet.add(img);
		}
	}
	
	public void draw(Graphics g) {
					
			background.draw(g);
			synchronized(iList) {
				for (UnitImage img : iList) {
					img.draw(g);
				}
			}
			synchronized (iBullet) {
				for (BulletImage bullet : iBullet) {
					bullet.draw(g);
				}
			}
			synchronized (iBullet) {
				for (BulletImage bullet : iBullet)
					for (UnitImage img : iList) {
						if (bullet.isLife())
							if (img.isCrash(bullet.getCenter(),
									bullet.getBulletDamage())) {
								bullet.setLifePoint(0);
								bullet.setBulletDamage(0);
							}
					}
			}
	}
	public void deleteBullet() {
		synchronized (iBullet) {
					
			for (BulletImage bullet : iBullet) {
				if(bullet.isLife())
					return;
			}
			iBullet.clear();
		}
	}
	public int getBulletSize() {
		return iBullet.size();
	}

}
